<?php
class Stack {
    /**
     *
     * @var <type> 
     */
    private $stack = array();
    /**
     * 
     */
    function __construct() {
    }
    /**
     *
     * @return <type>
     */
    public function is_empty() {
        return empty($this->stack);
    }
    /**
     *
     * @return <type> 
     */
    public function size() {
        return count($this->stack);
    }
    /**
     * Shove an element on the stack
     *
     * @param <type> $item
     * @return <type>
     */
    public function push($item) {
        if (array_push($this->stack, $item)) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * Pad the stack with $item until stack size = $amount
     *
     * @param <type> $amount
     * @param <type> $item
     * @return <type>
     */
    public function pad_to($amount, $item = 0) {
        if ($amount < 0 || $amount < $this->size()) {
            return false;
        } else {
            while ($this->size() != $amount) {
                $this->push($item);
            }
            return true;
        }
    }
    /**
     * Pad the stack with $item for $amount times
     *
     * @param <type> $amount
     * @param <type> $item
     * @return <type> 
     */
    public function pad_extra($amount, $item = 0) {
        if ($amount < 0) {
            return false;
        } else {
            for ($i=0; $i<$amount; $i++) {
                $this->push($item);
            }
            unset($i);
            return true;
        }
    }
    /**
     * Shoot off last item on the stack
     *
     * @return boolean
     */
    public function pop() {
        if (!$this->is_empty()) {
            array_pop($this->stack);
            return true;
        } else {
            return false;
        }
    }
    /**
     * Get certain element on the stack
     *
     * @param integer $position element position
     * @return <type> 
     */
    public function peek($position) {
        $elements = count($this->stack);
            if ($elements < $position) {
            unset($elements);
            return false;
        } else {
            unset($elements);
            return $this->stack[$position];
        }
    }
    /**
     * 
     */
    function __destruct() {
        unset($this->stack);
    }
}
